<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="6" :xs="24">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>个人信息</span>
          </div>
          <div>
            <div class="text-center" v-if="schoolId && schoolId > 0">
              <!-- <userAvatar /> -->
              <img :src="logoImg" class="schoolLogo" alt="" />
            </div>
            <ul class="list-group list-group-striped" v-if="!schoolId">
              <li class="list-group-item">
                <svg-icon icon-class="user" />用户名称
                <div class="pull-right">{{ user.userName }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="phone" />手机号码
                <div class="pull-right">{{ user.phonenumber }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="tree" />所属部门
                <div class="pull-right" v-if="user.dept">
                  {{ user.dept.deptName }} / {{ postGroup }}
                </div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="peoples" />所属角色
                <div class="pull-right">{{ roleGroup }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="date" />创建日期
                <div class="pull-right">{{ user.createTime }}</div>
              </li>
            </ul>
            <ul class="list-group list-group-striped" v-if="schoolId && schoolId > 0">
              <li class="list-group-item">
                <svg-icon icon-class="user" />学校编号
                <div class="pull-right">{{ schoolInfo.code }}</div>
              </li>

              <li class="list-group-item">
                <svg-icon icon-class="peoples" />联系人
                <div class="pull-right">{{ schoolInfo.contactPerson }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="peoples" />联系电话
                <div class="pull-right">{{ schoolInfo.contactPhone }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="peoples" />地址
                <div class="pull-right">{{ schoolInfo.address }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="date" />学校简介
                <div class="pull-right">{{ schoolInfo.schoolIntro }}</div>
              </li>
            </ul>
          </div>
        </el-card>
      </el-col>
      <el-col :span="18" :xs="24">
        <el-card>
          <div slot="header" class="clearfix">
            <span>基本资料</span>
          </div>
          <el-tabs v-model="activeTab">
            <el-tab-pane label="基本信息" name="userInfo" v-if="!schoolId">
              <userInfo :user="user" />
            </el-tab-pane>
            <!--            <el-tab-pane label="支付设置" name="payInfo" v-if="schoolId && schoolId > 0">-->
            <!--              <payInfo :user="user" />-->
            <!--            </el-tab-pane>-->
            <resetPwd />
          </el-tabs>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import userAvatar from "./userAvatar";
import payInfo from "./payInfo";
import userInfo from "./userInfo";
import resetPwd from "./resetPwd";
import { getUserProfile } from "@/api/system/user";
import store from "@/store";
import { getSchoolInfo } from "@/api/campus/school";

import logoImg from '@/assets/logo/logo.png'
export default {
  name: "Profile",
  components: { userAvatar, userInfo, resetPwd, payInfo },
  data() {
    return {
      user: {},
      roleGroup: {},
      postGroup: {},
      activeTab: "userInfo",
      schoolId: null,
      schoolInfo: {},
    };
  },
  created() {
    this.getUser();
    this.userInfoFun();
    this.getSchoolInfoFun();
  },
  activated() {
    this.getUser();
    this.userInfoFun();
    this.getSchoolInfoFun();
  },
  methods: {
    getSchoolInfoFun() {
      var that = this;
      getSchoolInfo().then((res) => {
        if (res.code == 200) {
          that.schoolInfo = res.data;
        }
      });
    },
    userInfoFun() {
      var that = this;
      store.dispatch("GetInfo").then((res) => {
        that.schoolId = res.data.user.schoolId;
        console.log(that.schoolId, "that.that.schoolId ");
        if (!that.schoolId) {
          that.activeTab = "userInfo";
        }
        if (that.schoolId && that.schoolId > 0) {
          that.activeTab = "payInfo";
        }
      });
    },
    getUser() {
      getUserProfile().then((response) => {
        this.user = response.data.user;
        this.roleGroup = response.data.roleGroup;
        this.postGroup = response.data.postGroup;
      });
    },
  },
};
</script>
<style>
.schoolLogo {
  width: 80px;
  height: 80px;
  border-radius: 50%;
}
</style>
